#!/bin/bash

echo "开始执行脚本"
#获取本机ipv4地址
ipv4_address=$(curl -s --max-time 5 ip.sb -4) || ipv4_address=$(curl -s "http://182.254.116.116/d?dn=myip.ipip.net&clientip=1" | sed 's/|/ /g'|awk '{print $2}') || ipv4_address=$(curl -s 4.ipw.cn)
# 获取本机的IPv6地址，最大等待时间5秒
#ipv6_address=$(curl -s --max-time 5 ip.sb -6) || ipv6_address=$(curl -s 6.ipw.cn)
# 进行端口计算
last_digit=$(ifconfig wlan0 | grep 'inet ' | awk '{print $2}' | cut -d'.' -f4)
mapped_port=$((10000 + (last_digit - 2) * 5))

# 输出本机IPv4地址（如果有）
[[ -n "$ipv4_address" ]] && echo "本机IPv4地址: $ipv4_address"

# 输出本机IPv6地址（如果有）
[[ -n "$ipv6_address" ]] && echo "本机IPv6地址: $ipv6_address"

# 输出映射端口及其递增值
echo "ip：映射端口"
for i in 0 1 2 3 4; do echo "$((10000 + i))= $ipv4_address:$((mapped_port + i))"; done

echo "脚本执行结束"